//
//  OrderView.m
//  RentTable
//
//  Created by mac on 2024/11/30.
//

#import "OrderView.h"

@interface OrderView()

@property(nonatomic, strong) UIImageView *orderImageView;
@property (nonatomic, strong) UILabel *hotPriceLabel;
@property (nonatomic, strong) UILabel *hotPriceDayLabel;
@property (nonatomic, strong) UILabel *hotLabel;
@property (nonatomic, strong) UILabel *priceLabel;

@end

@implementation OrderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}

- (void)setRentModel:(RentModel *)rentModel {
    _rentModel = rentModel;
    self.orderImageView.image = [UIImage imageNamed:rentModel.rentImage];
    self.hotPriceLabel.text = rentModel.rentTitle; //@"规格：［全新；黑色；3个月；×1］";
    self.hotPriceDayLabel.text = [NSString stringWithFormat:@"规格：［%@; %@; %ld个月]; ×%ld",rentModel.rentCondition,rentModel.rentColor,rentModel.rentPeriod,rentModel.rentCount];
    self.hotLabel.text = [NSString stringWithFormat:@"押金：  ¥%@",rentModel.rentDeposit];
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.1f/天",rentModel.rentPrice];
}

- (void)setUI {
    self.orderImageView = [UIImageView new];
    self.orderImageView.image = [UIImage imageNamed:@"1"];
    [self addSubview:self.orderImageView];
    self.orderImageView.layer.cornerRadius = 5;
    self.orderImageView.layer.masksToBounds = true;
    [self.orderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(17);
        make.top.mas_equalTo(18);
        make.size.mas_equalTo(CGSizeMake(83, 83));
    }];
    
    self.hotPriceLabel = [[UILabel alloc] init];
    self.hotPriceLabel.font = [UIFont pingFangSCRegularWithSize:16];
    self.hotPriceLabel.textColor = myRGBHex(0x333333);
    self.hotPriceLabel.text = @"台球桌标准型钢库中式黑八台球厅会所家用成";
    self.hotPriceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    self.hotPriceLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.hotPriceLabel];
    [self.hotPriceLabel sizeToFit];
    [self.hotPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.leading.equalTo(self.orderImageView.mas_trailing).offset(19);
        make.trailing.mas_offset(-5);
        make.height.mas_equalTo(20);
    }];
    
    self.hotPriceDayLabel = [[UILabel alloc] init];
    self.hotPriceDayLabel.font = [UIFont pingFangSCRegularWithSize:12];
    self.hotPriceDayLabel.textColor = myRGBHex(0x999999);
    self.hotPriceDayLabel.textAlignment = NSTextAlignmentLeft;
    self.hotPriceDayLabel.text = @"规格：［全新；黑色；3个月；×1］";
    [self addSubview:self.hotPriceDayLabel];
    [self.hotPriceDayLabel sizeToFit];
    [self.hotPriceDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hotPriceLabel.mas_bottom).offset(8);
        make.leading.equalTo(self.orderImageView.mas_trailing).offset(19);
        make.height.mas_equalTo(16);
    }];
    
    self.hotLabel = [[UILabel alloc] init];
    self.hotLabel.font = [UIFont pingFangSCRegularWithSize:12];
    self.hotLabel.textColor = myRGBHex(0x999999);
    self.hotLabel.text = @"押金：  ¥2000";
    self.hotLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.hotLabel];
    [self.hotLabel sizeToFit];
    [self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hotPriceDayLabel.mas_bottom).offset(4);
        make.leading.equalTo(self.orderImageView.mas_trailing).offset(19);
        make.trailing.mas_equalTo(-13);
        make.height.mas_equalTo(16);
    }];
    
    self.priceLabel = [[UILabel alloc] init];
    self.priceLabel.font = [UIFont pingFangSCRegularWithSize:14];
    self.priceLabel.textColor = myRGBHex(0xF51D1D);
    self.priceLabel.textAlignment = NSTextAlignmentLeft;
    self.priceLabel.text = @"¥59.9/天";
    [self addSubview:self.priceLabel];
    [self.priceLabel sizeToFit];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hotLabel.mas_bottom).offset(4);
        make.leading.equalTo(self.orderImageView.mas_trailing).offset(19);
        make.height.mas_equalTo(20);
    }];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}

@end
